package com.example.emos.wx.utils;

import lombok.Data;
import org.apache.http.HttpStatus;

import java.io.Serializable;

@Data
public class Result<T> {
    private String msg;
    private Integer code = HttpStatus.SC_OK;
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        return result;
    }

    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<T>();
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        return result;
    }

    public static <T> Result<T> success(String msg, T object) {
        Result<T> result = new Result<T>();
        result.msg = msg;
        result.data = object;
        return result;
    }

    public static <T> Result<T> error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static <T> Result<T> error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static <T> Result<T> error(int code, String msg) {
        Result<T> result = new Result<T>();
        result.msg = msg;
        result.code = code;
        return result;
    }
}
